package kadledav.adventure.framework.controll.commands.abstr;

import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;

import kadledav.adventure.framework.model.world.Player;

public abstract class ParameterActionCommand extends CommandAbstract {

	public ParameterActionCommand(PrintStream out, Scanner in, Player player) {
		super(out, in, player);
	}

	protected Integer parseFirstNumber(String[] userCommand, String objectPrefix) {
		if(userCommand.length < 2 ){
			return null;
		}
		return tryParseParameterNumber(objectPrefix, userCommand[1]);
	}
	
	protected Integer tryParseParameterNumber(String objectPrefix, String parameter) {
		if(!parameter.startsWith(objectPrefix)){
			return null;
		}
		try{
			return Integer.parseInt(parameter.substring(objectPrefix.length()));			
		}catch (NumberFormatException e){
			return null;
		}
	}
	
	protected boolean checkIsInRange(List<?> list,Integer index){
		if(index == null || list.size()-1<index || index<0){
			return false;
		}
		return true;
	}
	
}
